[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
bioskey() Keyboard Interface
#include <bios.h>
int bioskey(cmd);
int cmd; Operation to perform
bioskey() uses BIOS interrupt 0x16 to perform one of the following
keyboard operations specified by 'cmd':
0 Return the next keystroke. If the lower 8 bits are non-
zero, an ASCII character is returned. If the lower 8
bits are 0, the upper 8 bits represent an extended
keyboard code.
1 Check if a keystroke is available and return its value.
If 0 is returned, no keystroke is waiting. The keystroke
itself is kept until the next call to bioskey() with
'cmd' specified as 0.
2 Request the current shift key status. The value is
determined by ORing the following:
0x80 'Insert' toggled
0x40 'Caps Lock' toggled
0x20 'Num Lock' toggled
0x10 'Scroll Lock' toggled
0x08 'Alt' down
0x04 'Ctrl' down
0x02 'Left Shift' down
0x01 'Right Shift' down
Returns: A value based on the value of 'cmd', as described
above.
Portability: IBM PC and compatibles only.
-------------------------------- Example ---------------------------------
The following statements continually write out the value of the last
key pressed until a non-printing character or alt, ctrl or shift is
pressed.
#include <stdio.h> /* for printf and putch */
#include <bios.h> /* for bioskey */
#include <ctype.h> /* for isprint */
main()
{
int key, modifier_key = 0;
printf("Press a key\n");
key = bioskey(0); /* read first key */
while ((key & 0xFF) != 0 && isprint(key & 0xFF)
&& !modifier_key) {
putch(key);
modifier_key = bioskey(2) & 0x0F;/* get ctl, alt, shift */
if (bioskey(1)) /* if key is waiting */
key = bioskey(0); /* then read it */
}
}
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson